<template>
    <div>
        <h4>注册页面</h4>


        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="登录名">
                <el-input v-model="form.loginName"></el-input>
            </el-form-item>
            <el-form-item label="登录密码">
                <el-input  type="password" v-model="form.loginPassword"></el-input>
            </el-form-item>
            <el-form-item label="身份证号">
                <el-input v-model="form.cardNo"></el-input>
            </el-form-item>
            <el-form-item label="头像">
                <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
                    :show-file-list="false" :on-success="handleAvatarSuccess" >
                    <img v-if="form.headImg" :src="form.headImg" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item label="性别">
                <el-radio-group v-model="form.sex">
                    <el-radio label="男"></el-radio>
                    <el-radio label="女"></el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="eventSubmit">立即注册</el-button>
                <router-link to="/member/login">立即登录</router-link>
            </el-form-item>
        </el-form>

    </div>
</template>
<script>
export default {
    data() {
        return {
            form: {
                "loginName": "",
                "loginPassword": "",
                "name": "",
                "cardNo": "",
                "sex": "男",
                "headImg": "1.jpg"
            },
            imageUrl: ''
        }
    },
    methods: {
        //注册按钮提交事件
        eventSubmit() {
            let url=this.$baseUrl + '/member'
            let data=this.form
            this.$http.post(url,data).then(res=>{
                this.$message.info(res.data.message)
                if(res.data.code == 200){
                    console.log(1)
                }
            })
        },
        handleAvatarSuccess(res, file) {
            this.imageUrl = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
                this.$message.error('上传头像图片只能是 JPG 格式!');
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M;
        }
    }
}
</script>

<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}</style>